﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dv="clr-namespace:DevZest.Windows.DataVirtualization">

    <Style TargetType="{x:Type dv:VirtualListLoadingIndicator}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dv:VirtualListLoadingIndicator}">
                    <Border BorderThickness="0" Background="White">
                        <dv:LoadingAnimation VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="HasError" Value="True">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type dv:VirtualListLoadingIndicator}">
                            <Border Background="White">
                                <ScrollViewer VerticalScrollBarVisibility="Auto">
                                    <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center">
                                        <TextBlock TextWrapping="Wrap">
                                        <Run>We're sorry, an error occurred while loading data from server.</Run>
                                        <LineBreak />
                                        <Run>Please </Run>
                                        <Hyperlink CommandTarget="{Binding RelativeSource={x:Static RelativeSource.TemplatedParent}}" Command="{x:Static dv:VirtualListLoadingIndicator.RetryCommand}">retry</Hyperlink>
                                        <Run> or contact the support staff.</Run>
                                        </TextBlock>
                                        <Expander>
                                            <Expander.Header>
                                                <TextBlock>Detailed Error Message</TextBlock>
                                            </Expander.Header>
                                            <TextBox TextWrapping="Wrap" IsReadOnly="True" Text="{TemplateBinding ErrorMessage}" />
                                        </Expander>
                                    </StackPanel>
                                </ScrollViewer>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

    <!-- Setting VirtualListItemBase.AutoLoad to true will load the item when it's set to ListViewItem.Content property -->
    <Style TargetType="{x:Type ListViewItem}">
        <Setter Property="dv:VirtualListItemBase.AutoLoad" Value="true" />
    </Style>

    <!-- ColumnHeader template to show up and down arrow when sorted -->
    <DataTemplate x:Key="ListViewColumnHeaderTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <ContentPresenter ContentTemplate="{x:Null}" />
            <Path x:Name="Path" Grid.Column="1" Fill="Black" Margin="4,0,2,0" VerticalAlignment="Center" />
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding (dv:GridViewSort.SortOrder), RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type GridViewColumnHeader}}}" Value="None">
                <Setter TargetName="Path" Property="Visibility" Value="Collapsed" />
            </DataTrigger>
            <DataTrigger Binding="{Binding (dv:GridViewSort.SortOrder), RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type GridViewColumnHeader}}}" Value="Ascending">
                <Setter TargetName="Path" Property="Data" Value="M 0 4 L 4 0 L 8 4 Z" />
            </DataTrigger>
            <DataTrigger Binding="{Binding (dv:GridViewSort.SortOrder), RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type GridViewColumnHeader}}}" Value="Descending">
                <Setter TargetName="Path" Property="Data" Value="M 0 0 L 4 4 L 8 0 Z" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

</ResourceDictionary>